﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Sockets;

namespace ggprot
{
    public class GGSendMsg : GGHeader
    {
        private int recipient;
        private int seq;
        private int cls;
        private string message;
        private int plainOffset;
        private int attribOffset;
        private string htmlMessage;
        private byte[] attribs;

        public byte[] Attribs
        {
            get { return attribs; }
            set { attribs = value; }
        }

        public string HtmlMessage
        {
            get { return htmlMessage; }
            set { htmlMessage = value; }
        }

        public int AttribOffset
        {
            get { return attribOffset; }
            set { attribOffset = value; }
        }

        public int PlainOffset
        {
            get { return plainOffset; }
            set { plainOffset = value; }
        }

        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        public int Recipient
        {
            get { return recipient; }
            set { recipient = value; }
        }

        public int Seq
        {
            get { return seq; }
            set { seq = value; }
        }

        public int Cls
        {
            get { return cls; }
            set { cls = value; }
        }

        public override void Write(NetworkStream stream)
        {
            base.Write(stream);

            BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8);
            writer.Write(recipient);
            writer.Write(seq);
            writer.Write(cls);
            writer.Write(plainOffset);
            writer.Write(attribOffset);
            writer.Write(Encoding.UTF8.GetBytes(htmlMessage));
            if (!string.IsNullOrEmpty(message))
                writer.Write(Encoding.UTF8.GetBytes(message));
            if (attribs != null)
                writer.Write(attribs);

            writer.Flush();
        }
    }
}
